/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GUIboss.java
 *
 * Created on 20-dic-2009, 11:16:09
 */

package edu.upc.sma.visual;

import edu.upc.sma.agents.MySpringAgent;
import com.springrts.ai.AIFloat3;
import com.springrts.ai.oo.Unit;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import javax.swing.DefaultListModel;

/**
 *
 * @author xavi
 */
public class GUIboss extends javax.swing.JFrame implements SpringBoss{

    /** Creates new form GUIboss */
    public GUIboss(MySpringAgent agent) {
        this.setTitle("GUI boss");
        this.setLocation(100,100);
        
        this.agent = agent;
        teamUnitsList = new ArrayList<Unit>();
        enemiesRadarList = new ArrayList<Unit>();
        enemiesLOSList = new ArrayList<Unit>();
        constructionUnitNames = new ArrayList<String>();
        minesList = new ArrayList<AIFloat3>();
        groups = new ArrayList<Integer>();
        unitsGroup = new ArrayList<ArrayList>();

        eventsModel = new DefaultListModel();
        constructionHumanNamesModel = new DefaultListModel();
        teamUnitsModel = new DefaultListModel();
        enemiesRadarModel = new DefaultListModel();
        enemiesLOSmodel = new DefaultListModel();
        minesModel = new DefaultListModel();
        groupsModel = new DefaultListModel();
        groupUnitsModel = new DefaultListModel();

        initComponents();
        myInitComponents();

    }

    private void myInitComponents(){
        constructionUnitNames.add("armmex");
        //constructionUnitNames.add("cormex");
        constructionUnitNames.add("armsolar");
        //constructionUnitNames.add("corsolar");
        constructionUnitNames.add("armwin");
        //constructionUnitNames.add("corwin");
        constructionUnitNames.add("armmakr");
        //constructionUnitNames.add("cormakr");
        constructionUnitNames.add("armlab");
        //constructionUnitNames.add("corlab");;
        constructionUnitNames.add("armpeep");
        constructionUnitNames.add("armrock");
        constructionUnitNames.add("armham");
        constructionUnitNames.add("armck");
        //constructionUnitNames.add("corck");
        constructionUnitNames.add("armvp");
        //constructionUnitNames.add("corvp")
        constructionUnitNames.add("armstump");
        constructionUnitNames.add("armflash");
        constructionUnitNames.add("armsam");
        constructionUnitNames.add("armfav");
        constructionUnitNames.add("armcv");
        //constructionUnitNames.add("corcv");

        for(int i=0; i<constructionUnitNames.size(); i++){
            String name=constructionUnitNames.get(i);
            constructionHumanNamesModel.add(i,
                    agent.getUnitDef(name).getHumanName()+" ("+name+")");
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabelEvents = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jListEvents = new javax.swing.JList();
        jScrollPane2 = new javax.swing.JScrollPane();
        jListConstructionHumanNames = new javax.swing.JList();
        jLabelconstructionHumanNames = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jListTeamUnits = new javax.swing.JList(teamUnitsModel);
        jLabelteamUnits = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        jListEnemiesRadar = new javax.swing.JList(enemiesRadarModel);
        jLabelEnemiesRadar = new javax.swing.JLabel();
        jLabElenemiesLOS = new javax.swing.JLabel();
        jScrollPane5 = new javax.swing.JScrollPane();
        jListEnemiesLOS = new javax.swing.JList(enemiesLOSmodel);
        jButtonAttack = new javax.swing.JButton();
        jTextFieldXincrement = new javax.swing.JTextField();
        jLabelXincrement = new javax.swing.JLabel();
        jButtonConstruct = new javax.swing.JButton();
        jButtonMove = new javax.swing.JButton();
        jButtonNewGroup = new javax.swing.JButton();
        jLabelGroups = new javax.swing.JLabel();
        jTextFieldZincrement = new javax.swing.JTextField();
        jLabelZincrement = new javax.swing.JLabel();
        jScrollPane6 = new javax.swing.JScrollPane();
        jListMines = new javax.swing.JList(minesModel);
        jLabelEconomy = new javax.swing.JLabel();
        jLabelRsourceTipe = new javax.swing.JLabel();
        jLabelCurrentResource = new javax.swing.JLabel();
        jLabelIncomeResurce = new javax.swing.JLabel();
        jLabelStorageResource = new javax.swing.JLabel();
        jLabelUsageResource = new javax.swing.JLabel();
        jLabelResourceMetal = new javax.swing.JLabel();
        jLabelCurrentMetal = new javax.swing.JLabel();
        jLabelResourceEnergy = new javax.swing.JLabel();
        jLabelCurrentEnergy = new javax.swing.JLabel();
        jLabelIncomeMetal = new javax.swing.JLabel();
        jLabelIncomeEnergy = new javax.swing.JLabel();
        jLabelStorageMetal = new javax.swing.JLabel();
        jLabelStorageEnergy = new javax.swing.JLabel();
        jLabelUsageMetal = new javax.swing.JLabel();
        jLabelUsageEnergy = new javax.swing.JLabel();
        jCheckEnableMinesSelection = new javax.swing.JCheckBox();
        jButtonAddUnit = new javax.swing.JButton();
        jButtonRemoveGroup = new javax.swing.JButton();
        jLabelUnitsGroup = new javax.swing.JLabel();
        jScrollPane7 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList(groupsModel);
        jScrollPane8 = new javax.swing.JScrollPane();
        jList2 = new javax.swing.JList(groupUnitsModel);
        jCheckBoxEnebleGroups = new javax.swing.JCheckBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabelEvents.setText("Events:");

        jListEvents.setModel(eventsModel);
        jListEvents.setRequestFocusEnabled(false);
        jScrollPane1.setViewportView(jListEvents);

        jListConstructionHumanNames.setModel(constructionHumanNamesModel);
        jScrollPane2.setViewportView(jListConstructionHumanNames);

        jLabelconstructionHumanNames.setText("Constructions:");

        jScrollPane3.setViewportView(jListTeamUnits);

        jLabelteamUnits.setText("Team units:");

        jScrollPane4.setViewportView(jListEnemiesRadar);

        jLabelEnemiesRadar.setText("Enemies in radar:");

        jLabElenemiesLOS.setText("Enemies in LOS:");

        jScrollPane5.setViewportView(jListEnemiesLOS);

        jButtonAttack.setText("Attack");
        jButtonAttack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAttackActionPerformed(evt);
            }
        });

        jTextFieldXincrement.setText("0");

        jLabelXincrement.setText("x increment:");

        jButtonConstruct.setText("Construct");
        jButtonConstruct.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonConstructActionPerformed(evt);
            }
        });

        jButtonMove.setText("Move");
        jButtonMove.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonMoveActionPerformed(evt);
            }
        });

        jButtonNewGroup.setText("New");

        jLabelGroups.setText("Groups:");

        jTextFieldZincrement.setText("0");

        jLabelZincrement.setText("z increment:");

        jScrollPane6.setViewportView(jListMines);

        jLabelEconomy.setText("Economy:");

        jLabelRsourceTipe.setText("Resource:");

        jLabelCurrentResource.setText("Current:");

        jLabelIncomeResurce.setText("Income:");

        jLabelStorageResource.setText("Sroege:");

        jLabelUsageResource.setText("Usage:");

        jLabelResourceMetal.setText("metal?");

        jLabelCurrentMetal.setText("current m");

        jLabelResourceEnergy.setText("energy?");

        jLabelCurrentEnergy.setText("current e");

        jLabelIncomeMetal.setText("income m");

        jLabelIncomeEnergy.setText("income e");

        jLabelStorageMetal.setText("storage m");

        jLabelStorageEnergy.setText("storage e");

        jLabelUsageMetal.setText("usage m");

        jLabelUsageEnergy.setText("usage e");

        jCheckEnableMinesSelection.setText("Eneble mines selection");

        jButtonAddUnit.setText("Add unit");

        jButtonRemoveGroup.setText("Remove");

        jLabelUnitsGroup.setText("Units:");

        jScrollPane7.setViewportView(jList1);

        jScrollPane8.setViewportView(jList2);

        jCheckBoxEnebleGroups.setText("Eneble groups selection");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelEvents)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 270, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 142, Short.MAX_VALUE)
                    .addComponent(jLabelconstructionHumanNames, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabelZincrement)
                                    .addComponent(jLabelXincrement))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextFieldZincrement, javax.swing.GroupLayout.DEFAULT_SIZE, 50, Short.MAX_VALUE)
                                    .addComponent(jTextFieldXincrement, javax.swing.GroupLayout.DEFAULT_SIZE, 50, Short.MAX_VALUE)))
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jScrollPane6, 0, 0, Short.MAX_VALUE)
                                    .addComponent(jCheckEnableMinesSelection, javax.swing.GroupLayout.Alignment.TRAILING))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButtonConstruct)
                        .addGap(18, 18, 18)
                        .addComponent(jButtonMove)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jLabelteamUnits))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane3, 0, 0, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jButtonNewGroup)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButtonAddUnit)
                                .addGap(12, 12, 12)
                                .addComponent(jButtonRemoveGroup))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabelGroups)
                                    .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabelUnitsGroup)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 56, Short.MAX_VALUE))
                                    .addComponent(jScrollPane8, javax.swing.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jCheckBoxEnebleGroups)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))))
                .addGap(12, 12, 12)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabElenemiesLOS)
                            .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE)
                            .addComponent(jLabelEnemiesRadar)
                            .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(108, 108, 108)
                        .addComponent(jButtonAttack)))
                .addGap(26, 26, 26)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelEconomy)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelRsourceTipe)
                            .addComponent(jLabelCurrentResource)
                            .addComponent(jLabelIncomeResurce)
                            .addComponent(jLabelStorageResource)
                            .addComponent(jLabelUsageResource))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(1, 1, 1)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabelResourceMetal)
                                    .addComponent(jLabelCurrentMetal)
                                    .addComponent(jLabelIncomeMetal)))
                            .addComponent(jLabelUsageMetal)
                            .addComponent(jLabelStorageMetal))))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelUsageEnergy)
                    .addComponent(jLabelStorageEnergy)
                    .addComponent(jLabelIncomeEnergy)
                    .addComponent(jLabelCurrentEnergy)
                    .addComponent(jLabelResourceEnergy))
                .addGap(156, 156, 156))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelEvents)
                    .addComponent(jLabelconstructionHumanNames)
                    .addComponent(jLabelEnemiesRadar)
                    .addComponent(jLabelEconomy)
                    .addComponent(jLabelteamUnits))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE)
                                        .addComponent(jScrollPane4, 0, 0, Short.MAX_VALUE))
                                    .addComponent(jScrollPane3, 0, 0, Short.MAX_VALUE))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(6, 6, 6)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jTextFieldXincrement, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jButtonNewGroup)
                                            .addComponent(jButtonAddUnit)
                                            .addComponent(jButtonRemoveGroup)
                                            .addComponent(jLabelXincrement)))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(12, 12, 12)
                                        .addComponent(jLabElenemiesLOS)))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(12, 12, 12)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(26, 26, 26)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addGroup(layout.createSequentialGroup()
                                                        .addComponent(jCheckEnableMinesSelection)
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE))
                                                    .addGroup(layout.createSequentialGroup()
                                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                            .addComponent(jScrollPane8, 0, 0, Short.MAX_VALUE)
                                                            .addComponent(jScrollPane7, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE))
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                        .addComponent(jCheckBoxEnebleGroups))))))
                                    .addGroup(layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jLabelGroups)
                                            .addComponent(jTextFieldZincrement, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabelZincrement)
                                            .addComponent(jLabelUnitsGroup))))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jButtonMove)
                                        .addComponent(jButtonConstruct))
                                    .addComponent(jButtonAttack)))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 374, Short.MAX_VALUE))
                        .addContainerGap())
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabelRsourceTipe)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jLabelCurrentResource)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jLabelIncomeResurce)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jLabelStorageResource)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jLabelUsageResource))
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(23, 23, 23)
                                    .addComponent(jLabelCurrentMetal)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jLabelIncomeMetal))
                                .addComponent(jLabelResourceMetal))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jLabelStorageMetal)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jLabelUsageMetal))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(23, 23, 23)
                                    .addComponent(jLabelCurrentEnergy)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jLabelIncomeEnergy))
                                .addComponent(jLabelResourceEnergy))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jLabelStorageEnergy)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jLabelUsageEnergy)))))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonMoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonMoveActionPerformed
        this.move();
    }//GEN-LAST:event_jButtonMoveActionPerformed

    private void jButtonConstructActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonConstructActionPerformed
        this.construct();
    }//GEN-LAST:event_jButtonConstructActionPerformed

    private void jButtonAttackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAttackActionPerformed
        this.attack();
    }//GEN-LAST:event_jButtonAttackActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GUIboss(new MySpringAgent()).setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAddUnit;
    private javax.swing.JButton jButtonAttack;
    private javax.swing.JButton jButtonConstruct;
    private javax.swing.JButton jButtonMove;
    private javax.swing.JButton jButtonNewGroup;
    private javax.swing.JButton jButtonRemoveGroup;
    private javax.swing.JCheckBox jCheckBoxEnebleGroups;
    private javax.swing.JCheckBox jCheckEnableMinesSelection;
    private javax.swing.JLabel jLabElenemiesLOS;
    private javax.swing.JLabel jLabelCurrentEnergy;
    private javax.swing.JLabel jLabelCurrentMetal;
    private javax.swing.JLabel jLabelCurrentResource;
    private javax.swing.JLabel jLabelEconomy;
    private javax.swing.JLabel jLabelEnemiesRadar;
    private javax.swing.JLabel jLabelEvents;
    private javax.swing.JLabel jLabelGroups;
    private javax.swing.JLabel jLabelIncomeEnergy;
    private javax.swing.JLabel jLabelIncomeMetal;
    private javax.swing.JLabel jLabelIncomeResurce;
    private javax.swing.JLabel jLabelResourceEnergy;
    private javax.swing.JLabel jLabelResourceMetal;
    private javax.swing.JLabel jLabelRsourceTipe;
    private javax.swing.JLabel jLabelStorageEnergy;
    private javax.swing.JLabel jLabelStorageMetal;
    private javax.swing.JLabel jLabelStorageResource;
    private javax.swing.JLabel jLabelUnitsGroup;
    private javax.swing.JLabel jLabelUsageEnergy;
    private javax.swing.JLabel jLabelUsageMetal;
    private javax.swing.JLabel jLabelUsageResource;
    private javax.swing.JLabel jLabelXincrement;
    private javax.swing.JLabel jLabelZincrement;
    private javax.swing.JLabel jLabelconstructionHumanNames;
    private javax.swing.JLabel jLabelteamUnits;
    private javax.swing.JList jList1;
    private javax.swing.JList jList2;
    private javax.swing.JList jListConstructionHumanNames;
    private javax.swing.JList jListEnemiesLOS;
    private javax.swing.JList jListEnemiesRadar;
    private javax.swing.JList jListEvents;
    private javax.swing.JList jListMines;
    private javax.swing.JList jListTeamUnits;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JTextField jTextFieldXincrement;
    private javax.swing.JTextField jTextFieldZincrement;
    // End of variables declaration//GEN-END:variables
    private MySpringAgent agent;
    private DefaultListModel eventsModel, constructionHumanNamesModel,
            teamUnitsModel, enemiesRadarModel, enemiesLOSmodel, minesModel,
            groupsModel, groupUnitsModel;
    private List<Unit> teamUnitsList, enemiesRadarList, enemiesLOSList;
    private List<AIFloat3> minesList;
    private ArrayList<String> constructionUnitNames;
    ArrayList<Integer> groups;
    ArrayList<ArrayList> unitsGroup;


    // Private methods
    
    /**
     * Adds element <code>m</code> in <code>model</code>.  If <code>list</code>
     * and <code>l</code> are not <code>null</code>, also adds <code>l</code> in
     * <code>list</code>
     *
     * @param model
     * @param m
     * @param list
     * @param l
     */
    private void addElement(DefaultListModel model, String m, List<Unit> list, Unit l){
        model.addElement(m);
        if(list!=null) list.add(l);
    }

    @Override
    public void move(){
        int unit = jListTeamUnits.getSelectedIndex();
        int metal = jListMines.getSelectedIndex();
        float x,z;
        if(unit >= 0){
            if(jCheckEnableMinesSelection.isSelected() && metal >= 0){
                AIFloat3 p = minesList.get(metal);
                x = p.x;
                z = p.z;
            }
            else{
                x = Float.parseFloat(jTextFieldXincrement.getText());
                z = Float.parseFloat(jTextFieldZincrement.getText());
            }
            agent.move(teamUnitsList.get(unit), x, z);
        }
    }

    public void construct(){
        int constructor = jListTeamUnits.getSelectedIndex();
        int construction = jListConstructionHumanNames.getSelectedIndex();
        int metal = jListMines.getSelectedIndex();
        float x,z;
        if(constructor >= 0 && construction >= 0){
            if(jCheckEnableMinesSelection.isSelected() && metal >= 0){
                AIFloat3 p = minesList.get(metal);
                x = p.x;
                z = p.z;
            }
            else{
                x = Float.parseFloat(jTextFieldXincrement.getText());
                z = Float.parseFloat(jTextFieldZincrement.getText());
            }
            agent.construct(teamUnitsList.get(constructor),
                    constructionUnitNames.get(construction),x, z);
        }
    }

    @Override
    public void constructUnit(String unit, int nUnits, int id){
        for(int i=0; i<nUnits; i++){
            while(agent.defaultUnitConstruct(unit,id)<0){}
        }
    }

    @Override
    public void constructBuilding(String building){
        while(agent.defaultBuildingConstruct(building)<0){}
    }

    @Override
    public void attack(){
        int attacker = jListTeamUnits.getSelectedIndex();
        int enemy = jListEnemiesLOS.getSelectedIndex();
        if(attacker >= 0 && enemy >= 0){
            agent.attack(teamUnitsList.get(attacker), enemiesLOSList.get(enemy));
        }
    }

    // ++++++++++++++++++++++++   CALLBACKS   ++++++++++++++++++++++++

    @Override
    public Vector<Integer> getMapMeasures(){
        return agent.getMapMeasures();
    }

    @Override
    public Vector<Float> getCommanderPosition(){
        return agent.getCommanderPosition();
    }
    
    @Override
    public float getMetalAvailable(){
        return agent.getMetalAvailable();
    }

    @Override
    public float getEnergyAvailable(){
        return agent.getEnergyAvailable();
    }

    @Override
    public float getMetalCost(String unit){
        return agent.getMetalCost( unit);
    }

    @Override
    public float getEnergyCost(String unit){
        return agent.getEnergyCost( unit);
    }

    @Override
    public String getDependence(String unit){
        return agent.getDependence(unit);
    }

    // +++++++++++++++++++++++++     API     +++++++++++++++++++++++++

    @Override
    public void addEvent(String event){
        this.addElement(eventsModel, event, null, null);
    }
    
    @Override
    public void gameStarted() {
        this.addElement(eventsModel, "<Game Starts>", null, null);
    }

    @Override
    public void buildingConstructed(String building) {
        this.addElement(eventsModel, "<"+building+" done!>", null, null);
    }

    @Override
    public void orderUnitsConstructed(int id) {
        this.addElement(eventsModel, "<"+id+" done!>", null, null);
    }

    @Override
    public void enemyCommanderEnterLOS(Vector<Float> p){
        this.addElement(eventsModel, "<Enemy commander in LOS ("+p.get(0)+","+
                p.get(2)+")>", null, null);
    }

    @Override
    public void refreshTeamUnits(List<Unit> units){
        teamUnitsModel.removeAllElements();
        teamUnitsList.clear();
        for(Unit e : units){
            this.addElement(teamUnitsModel,
                    e.getUnitId()+" ("+e.getDef().getHumanName()+")",
                    teamUnitsList, e);
        }
    }

    @Override
    public void refreshEnemyLOSandRadar(List<Unit> enemiesLOS, List<Unit> enemiesRadar){
        if(enemiesLOS.size()!=enemiesLOSList.size() ||
                !enemiesLOSList.containsAll(enemiesLOS)){
            enemiesLOSmodel.removeAllElements();
            enemiesLOSList.clear();
            if(enemiesLOS.size()>0){
                for(Unit e : enemiesLOS){
                    this.addElement(enemiesLOSmodel,
                            e.getUnitId()+" ("+e.getDef().getHumanName()+")",
                            enemiesLOSList, e);
                }
            }
        }
        if(enemiesRadar.size()!=enemiesRadarList.size() ||
                !enemiesRadarList.containsAll(enemiesRadar)){
            enemiesRadarModel.removeAllElements();
            enemiesRadarList.clear();
            if(enemiesRadar.size()>0){
                for(Unit e : enemiesRadar){
                    this.addElement(enemiesRadarModel,
                            //e.getUnitId()+" ("+e.getDef().getHumanName()+")",
                            ""+e.getUnitId(),
                            enemiesRadarList, e);
                }
            }
        }
    }

    /**
     *
     * @param mapInfo
     * @param cp commander position
     */
    @Override
    public void refreshMines(List<AIFloat3> minesList) throws Exception{
        this.minesList = minesList;
        minesModel.removeAllElements();
        for(int i=0; i<minesList.size(); i++){
            AIFloat3 p = minesList.get(i);
            minesModel.addElement(" ("+p.x+","+p.y+","+p.z+")");
        }
    }

    @Override
    public void refreshResourcesMake(float metal, float energy){
        jLabelRsourceTipe.setText("Metal: "+metal);
        jLabelCurrentResource.setText("Energy: "+energy);
    }

    @Override
    public void refreshResourcesUse(float metal, float energy){
        jLabelStorageResource.setText("Metal: "+metal);
        jLabelUsageResource.setText("Energy: "+energy);
    }

    @Override
    public void refreshMetalEconomy(String resource,
            float current, float income,float storage, float usage){
        jLabelResourceMetal.setText(resource);
        jLabelCurrentMetal.setText(String.valueOf(current));
        jLabelIncomeMetal.setText(String.valueOf(income));
        jLabelStorageMetal.setText(String.valueOf(storage));
        jLabelUsageMetal.setText(String.valueOf(usage));
    }

    @Override
    public void refreshEnergyEconomy(String resource, float current,
            float income,float storage, float usage){
        jLabelResourceEnergy.setText(resource);
        jLabelCurrentEnergy.setText(String.valueOf(current));
        jLabelIncomeEnergy.setText(String.valueOf(income));
        jLabelStorageEnergy.setText(String.valueOf(storage));
        jLabelUsageEnergy.setText(String.valueOf(usage));
    }
}
